import React from "react";

export default class MyInput extends React.Component {
  state = {
    name: "",
  };

  inputChange (e) {
    this.setState({
      name: e.target.value
    })
  }

  setName () {
    this.setState({
      name: '张三'
    })
  }

  render() {
    return (
      <div>
        <div>
          名字：
          <input onChange={(e) => this.inputChange(e)} value={this.state.name} type="text" />
          <button onClick={() => this.setName()}>给输入框赋值为张三</button>
        </div>
      </div>
    );
  }
}
